package com.googlecode.bpmcenter.controller;
 
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import org.springframework.dao.DataAccessException;

import com.googlecode.bpmcenter.model.Partner;
import com.googlecode.bpmcenter.service.PartnerService;

@ManagedBean(name="partnerController")
@RequestScoped
public class PartnerController implements Serializable {
 
    private static final long serialVersionUID = 1L;
 
    @ManagedProperty(value="#{partnerService}")
    PartnerService partnerService;
    
    List<Partner> partnersList;
 
    private Long id;
    private String name;
 
    public String addPartner() {
        try {
        	
            Partner partner = new Partner();
            partner.setId(getId());
            partner.setName(getName());
            getPartnerService().addPartner(partner);
    			
        } catch (DataAccessException e) {
            e.printStackTrace();
        }   
 
        return "partnerList";
    }
 
    public void reset() {
        this.setId(0L);
        this.setName("");
    }
 
    public List<Partner> getPartnersList() {
        partnersList = new ArrayList<Partner>();
        partnersList.addAll(getPartnerService().getPartners());
        return partnersList;
    }
 
    public void setPartnersList(List<Partner> partnersList) {
        this.partnersList = partnersList;
    }
 
    public Long getId() {
        return id;
    }
 
    public void setId(Long id) {
        this.id = id;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
		public PartnerService getPartnerService() {
    	return partnerService;
    }

		public void setPartnerService(PartnerService partnerService) {
    	this.partnerService = partnerService;
    }

}